<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>



	<div id="openWin" class="easyui-window" inline="true" closed="true" iconCls="icon-save" style="width:500px;height:620px;padding:5px;">
		<div class="easyui-layout" fit="true">
			<div region="center" border="false" style="padding:10px;background:#fff;border:1px solid #ccc;">

				<input type="hidden" name="projectId" id="projectId" />
				<table>
					<tr>
						<td style="vertical-align: top;"><label>项目名称</label></td>
						<td>
							<input type="text" name="projectName" id="projectName" class="easyui-validatebox" required="true" style="width: 120px;"/>
						</td>
						<td style="vertical-align: top;"><label>项目编号</label></td>
						<td>
							<input type="text" name="projectCode" id="projectCode" class="easyui-validatebox" required="true" style="width: 120px;" />
						</td>
					</tr>
					<tr>
						<td style="vertical-align: top;"><label>所属公司</label></td>
						<td>
							<s:hidden name="subsidiaryId" />
							<input type="text" name="displaySubsidiaryName" id="displaySubsidiaryName" 
								class="easyui-validatebox" required="true" style="width: 120px;" 
								readonly onclick="popUpWin('subsidiaryId', 'displaySubsidiaryName');" />
						</td>
						<td style="vertical-align: top;"><label>项目经理</label></td>
						<td>
							<s:select id="managerId" name="managerId" list="#request.employeeInfoList" listKey="employeeId" listValue="employeeName" theme="simple" style="width: 120px;" />
						</td>
					</tr>
					<tr>
						<td style="vertical-align: top;"><label>立项日期</label></td>
						<td>
							<input type="text" id="startTime" name="startTime" class="easyui-validatebox" required="true" style="width: 120px;" />
						</td>
						<td style="vertical-align: top;"><label>结项日期</label></td>
						<td>
							<input type="text" id="endTime" name="endTime" class="easyui-validatebox" required="true" style="width: 120px;"  />
						</td>
					</tr>
					<tr>
						<td style="vertical-align: top;"><label>预算金额</label></td>
						<td colspan="3">
							<input type="text" name="budgetAmount" id="budgetAmount" class="easyui-validatebox" required="true" style="width: 120px;"/>
						</td>
					</tr>
					<tr>
						<td style="vertical-align: top;"><label>项目内容</label></td>
						<td colspan="3">
							<textarea rows="3" cols="35" name="content" id="content"></textarea>
						</td>
					</tr>
					<tr>
						<td style="vertical-align: top;"><label>备注</label></td>
						<td colspan="3">
							<textarea rows="3" cols="35" name="remark" id="remark"></textarea>
						</td>
					</tr>
				</table>
			</div>
			<div region="south" border="false" style="text-align:right;padding:5px 0;">
				<a class="easyui-linkbutton" iconCls="icon-ok" href="javascript:void(0)" onclick="save();">保存</a>
				<a class="easyui-linkbutton" iconCls="icon-cancel" href="javascript:void(0)" onclick="$('#openWin').window('close');">关闭</a>
			</div>
		</div>
	</div>
 
<script>

  $(function() {
	  
	  initDatePicker("startTime");
	  initDatePicker("endTime");
	   
   });
  
  function save() {
	  if ($('#projectName').validatebox('isValid')
			  && $('#projectCode').validatebox('isValid')
			  && $('#budgetAmount').validatebox('isValid')
			  && $('#displaySubsidiaryName').validatebox('isValid')
			  && checkAmount($('#budgetAmount').val())) {
		  $("#queryForm").submit();
	  }
  }
  
  function openAddForm() {
	  $("#projectId").val("");
	  
	  openWin('新建项目', 'project_addProjectAction.action');
  }
  
  function openWin(title, action) {
	  $("#queryForm").attr("action", action);
	  $('#openWin').window({
			title: title,
			modal: true,
			shadow: false,
			closed: false,
			collapsible: false,
			minimizable: false,
			maximizable: false,
			width: 450,
			height: 380
		});
  }
  
  function openModifyForm() {
	  
	  var rows = $('#dataTable').datagrid('getSelections');
	  if (rows.length <= 0) {
		  $.messager.alert('信息','请选择一条记录！','info');
		  return;
	  } else if (rows.length > 1) {
		  $.messager.alert('信息','只能选择一条记录！','info');
		  return;
	  }
	  
	  var url = "project_getProjectAction.action?projectId="+rows[0].projectId;
	  $.getJSON(url, function(data){
		  
		  if (data != null) {
			  $("#projectName").val(data.projectInfo.projectName);
			  $("#projectCode").val(data.projectInfo.projectCode);
			  $("#subsidiaryId").val(data.projectInfo.subsidiaryId);
			  $("#displaySubsidiaryName").val(data.projectInfo.subsidiaryName);
			  $("#managerId").val(data.projectInfo.managerId);
			  $("#budgetAmount").val(data.projectInfo.budgetAmount);
			  
			  var startTime;
			  var endTime;
			  if (data.projectInfo.startTime != null
					  && data.projectInfo.startTime != '') {
				  startTime = new Date(data.projectInfo.startTime).format("yyyy-MM-dd");
			  } else {
				  startTime = "";
			  }
			  if (data.projectInfo.endTime != null
					  && data.projectInfo.endTime != '') {
				  endTime = new Date(data.projectInfo.endTime).format("yyyy-MM-dd");
			  } else {
				  endTime = "";
			  }
			  $("#startTime").datebox('setValue', startTime);
			  $("#endTime").datebox('setValue', endTime);
			  
			  $("#content").val(data.projectInfo.content);
			  $("#remark").val(data.projectInfo.remark);
			  $("#projectId").val(data.projectInfo.projectId);

			  openWin('修改项目', 'project_modifyProjectAction.action');
		  }
		});
	}
    </script>
